package moe.loliserver;

import java.text.SimpleDateFormat;
import java.util.*;

public class LanguagesMap {

    private static String sysDate = "";
    private static Map<String, String> CN = new HashMap<>();
    private static Map<String, String> EN = new HashMap<>();
    private static Map<String, String> current;

    static {
        CN.put("loli.eula", date() + "[INFO]: 你需要同意 Minecraft EULA (https://account.mojang.com/documents/minecraft_eula) 才可以使用, 继续使用则视为同意, 将在5秒后启动..");
        CN.put("loli.updatenull", date() + "[INFO]: 更新检测异常, 请提交至Github issues");
        CN.put("loli.noupdate", date() + "[INFO]: 你正在运行最新版本的LoliServer, 无需更新");
        CN.put("loli.outdate", date() + "[INFO]: 你运行的LoliServer不是最新版本, 自动更新开始, 最新版本( %s )");
        CN.put("loli.update", date()  + "[INFO]: 文件 %s 下载完毕, LoliServer将会进行重新启动服务端线程");
        CN.put("loli.errorjava", date() + "[INFO]: LoliServer正运行于不兼容的Java版本, 请更换Java版本至JDK8/JDK11");
        CN.put("loli.compatiblejava", date() + "[INFO]: JAVA版本验证完成, LoliServer进程将继续进行");
        CN.put("loli.editbash", date() + "[INFO]: 自动安装已完成, 请手动修改启动脚本或核心名, 删除旧核心");
        CN.put("loli.editbash1", date() + "[INFO]: LoliServer线程终止, 请修改核心名或启动脚本重新启动.");
        CN.put("launch.lib_failure_check", date() + "[INFO]: 文件 %s 校验失败, 你也可以手动下载: %s");
        CN.put("launch.lib_failure_download", date() + "[INFO]: 下载文件失败(HTTP状态: %s)");
        CN.put("launch.lib_downloading", date() + "[INFO]: 正在下载文件 %s 大小: %s");
        CN.put("launch.lib_global_percentage", date() + "[INFO]: 全局下载进度 : ");
        EN.put("loli.eula", date() + "[INFO]: You need to agree with Minecraft EULA (https://account.mojang.com/documents/minecraft_eula) before you can continue to use it. If you continue to use it, it will be regarded as consent. The server will start in 5 seconds..");
        EN.put("loli.errorjava", date() + "[INFO]: Loliserver is running in an incompatible java version. Please change the Java version to JDK8/JDK11");
        EN.put("loli.compatiblejava", date() + "[INFO]: The Java version verification is completed, and the LoliServer process will continue");
        EN.put("loli.update", date() + "[INFO]: After downloading the file %s , LoliServer will restart the server process");
        EN.put("loli.updatenull", date() + "[INFO]: UpdateCheck Error, Please refer to Github issues");
        EN.put("loli.noupdate", date() + "[INFO]: you are running the latest version of LoliServer, no need to update");
        EN.put("loli.outdate", date() + "[INFO]: The LoliServer you are running is not the latest version. Auto update starts. latest version( %s )");
        EN.put("loli.editbash", date() + "[INFO]: Automatic installation is completed. Please modify the startup script or core name manually to delete the old core");
        EN.put("loli.editbash1", date() + "[INFO]: LoliServer thread terminated, please modify the core name or restart the startup script");
        EN.put("launch.lib_failure_check", date() + "[INFO]: File %s verification failed, URL: %s");
        EN.put("launch.lib_failure_download", date() + "[INFO]: File download failed(HTTP Status: %s), URL: %s");
        EN.put("launch.lib_downloading", date() + "[INFO]: Downloading %s Size: %s");
        EN.put("launch.lib_global_percentage", date() + "[INFO]: Percentage of global Downloads : ");

        //Server
        CN.put("callWarn", "从[%s]检测到调用: [%s], 详情查看栈堆/Debug日志");
        CN.put("nullError", "Class [%s] 为空或 Method [%s] 意外的返回了null");
        CN.put("startError", date() + "[ERROR]: 在试图运行LoliServer时发生异常, 你需要把错误提交给LoliServer开发组");
        CN.put("startWithJDK16", date() + "[WARN]: 你正试图使用JDK16运行LoliServer, 但插件/模组兼容性我们无力解决");
        CN.put("startWithJDK16_1", date() + "[WARN]: 请在启动参数添加以下参数: ");
        EN.put("callWarn", "Call detected from [%s]: [%s], See stacktrace/debug.log for details");
        EN.put("nullError", "Class [%s] is empty or Method [%s] unexpectedly returned null");
        EN.put("startError", date() + "[ERROR]: An error occurs with the server start. You can ask for help to the LoliServer support on GitHub.");
        EN.put("startWithJDK16", date() + "[WARN]: You are trying to run LoliServer with JDK16, but we can't solve the Plugin/Mod compatibility");
        EN.put("startWithJDK16_1", date() + "[WARN]: Please add the following parameters to the startup parameters: ");

        // Args
        CN.put("j16Args", date() + "[INFO]: %s");
        EN.put("j16Args", date() + "[INFO]: %s");

        // FakePlayer
        CN.put("fakePlayerWarn", "试图为FakePlayer增加Operater权限");
        EN.put("fakePlayerWarn", "Attempt to add Operator permission for FakePlayer");

        current = ("zh".equals(Locale.getDefault().getLanguage()) ? CN : EN);

    }

    public static String date(){
        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        sysDate = sdf.format(dt);

        return "[" +  sysDate + "]";
    }

    public static String i18nGet(String text) {
        return current.getOrDefault(text, "null");
    }

}
